package com.feng.leetcode;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @author feng
 * @decrition 可以由 | - L 三种图形，其中|占据一列，-占据两列，L必须由两个组成占据3列且可以在中见加上—则占据五列
 * @date 2022/11/1217:23
 */
public class L790 {
    public static int numTilings(int n) {
        Set<String> set = new LinkedHashSet<>();
        backtrack(n, set, "");
        int result = set.size();
        for (String s : set) {
            System.out.println(s);
        }
        return result;
    }

    private static void backtrack(int n, Set<String> set, String str) {
        if (n == 0) {
            set.add(str);
            return;
        }
        if (n < 0) {
            return;
        }
        backtrack(n - 1, set, str + "|");
        if (n >= 2) {
            backtrack(n - 2, set, str + "-");
        }
        if (n >= 3) {
            int count = 0;
            for (int i = 3; i <= n;) {
                String temp = "";
                for (int j = 0; j < count; j++) {
                    temp += "-";
                }
                backtrack(n - i, set, str + "L" + temp + "F");
                backtrack(n - i, set, str + "F" + temp + "L");
                count++;
                i += 2;
            }
        }
        if (n >= 4) {
            int count = 0;
            for (int i = 4; i <= n;) {
                String temp = "";
                for (int j = 0; j < count; j++) {
                    temp += "-";
                }
                backtrack(n - i, set, str + "L" + temp + "L");
                backtrack(n - i, set, str + "F" + temp + "F");
                count++;
                i += 2;
            }
        }
    }

    public static void main(String[] args) {
        int result = numTilings(7);
        System.out.println(result);

        Set<String> set = new LinkedHashSet<>();
        String str = "";
        int n = 7;
        if (n >= 3) {
            int count = 0;
            for (int i = 3; i <= n;) {
                String temp = "";
                for (int j = 0; j < count; j++) {
                    temp += "-";
                }
                str = str + "L" + temp + "F";
                /*backtrack(n - i, set, str + "L" + temp + "F");
                backtrack(n - i, set, str + "F" + temp + "L");*/
                count++;
                i += 2;
            }
        }
    }
}
